package com.team.arms.political.service.impl;


import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.team.arms.political.domain.PoliReviewInfo;
import com.team.arms.political.domain.vo.Culvo;
import com.team.arms.political.mapper.PoliReviewInfoMapper;
import com.team.arms.political.service.PoliReviewInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 *
 */
@Service
public class PoliReviewInfoServiceImpl extends ServiceImpl<PoliReviewInfoMapper, PoliReviewInfo>
    implements PoliReviewInfoService {

    @Autowired
    PoliReviewInfoMapper poliReviewInfoMapper;

    @Override
    public List<Culvo> selectcul() {
        return poliReviewInfoMapper.selectcul();
    }


    @Override
    public void exportpoli(HttpServletResponse response,List list,Class T,String name) {

        //设置下载信息
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        //这里URLEncoder.encode可以防止中文乱码
        /*String s = T.getName();

        String[] split = s.split("\\.");

//        for (String s2:split
//             ) {
//            System.out.println(s2);
//        }
        String name="";

        Random random = new Random();
        int randomNum = random.nextInt(100) + 1;

        name=split[split.length-1]+randomNum;*/
        String fileName = name;
        System.out.println(fileName);
        response.setCharacterEncoding("UTF-8");
        try {
            response.setHeader("Content-disposition", "attachment;filename=" +new String(fileName.getBytes(StandardCharsets.UTF_8),"ISO8859-1")  + ".xlsx");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        //查询数据库

//            List<DovecoteDailyVo> dovecoteDailyVoList = ConvertUtil.java.convert(dovecoteDailies, DovecoteDailyVo.class);
        //调用方法进行写操作
        try {
            EasyExcel.write(response.getOutputStream(), T).sheet("yingzheng")
                    .doWrite(list);
        } catch (Exception e) {
            e.printStackTrace();

        }
    }
}




